<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  <meta name="description" content="">
  <meta name="author" content="ThemeBucket">
  <link rel="shortcut icon" href="#" type="image/png">

  <title>Form Validation</title>

    <div th:include="commons :: comhead"></div>


</head>

<body class="sticky-header">

<section>
    <!-- left side start-->
    <div th:replace="commons :: #left"></div>
    <!-- left side end-->
    
    <!-- main content start-->
    <div class="main-content" >

        <!-- header section start-->
        <div th:replace="commons :: #search"></div>
        <!-- header section end-->

        <!-- page heading start-->
        <div class="page-heading">
            <h3>
                Form Validation
            </h3>
            <ul class="breadcrumb">
                <li>
                    <a href="#">主页</a>
                </li>
                <li class="active"> 基本信息 </li>
                <li class="active"> 修改信息 </li>
            </ul>
        </div>
        <!-- page heading end-->

        <!--body wrapper start-->
        <div class="wrapper">
            <div class="row">
                <div class="col-lg-12">
                    <section class="panel">
                        <header class="panel-heading">
                            Basic validations
                        </header>
                        <div class="panel-body">
                            <form role="form" class="form-horizontal adminex-form" id="form" th:action="@{/boss_edit}" method="post">
                                <div class="form-group has-success">
                                    <label class="col-lg-2 control-label">员工ID</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" name="id" id="id" th:value="${userDto.id}" class="form-control" readonly>
                                    </div>
                                </div>
                                <div class="form-group has-success">
                                    <label class="col-lg-2 control-label">登录昵称</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" id="username" name="username" th:value="${userDto.username}" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group has-error">
                                    <label class="col-lg-2 control-label">真实姓名</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" name="ename" id="ename" th:value="${userDto.ename}" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group has-warning">
                                    <label class="col-lg-2 control-label" >邮箱</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" id="email" name="email" th:value="${userDto.email}" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group has-warning">
                                    <label class="col-lg-2 control-label" >电话</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" id="tel" name="tel" th:value="${userDto.tel}" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group has-warning">
                                    <label class="col-lg-2 control-label" >地址</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" id="address" name="address" th:value="${userDto.address}" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group has-warning">
                                    <label class="col-lg-2 control-label">上级编号</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" name="mgr" id="mgr" th:value="${userDto.mgr}" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group has-warning">
                                    <label class="col-lg-2 control-label">入职时间</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" name="hiredate" id="hiredate" th:value="${#dates.format(userDto.hiredate,'yyyy/MM/dd HH:mm')}" class="form-control" readonly>
                                    </div>
                                </div>
                                <div class="form-group has-warning">
                                    <label class="col-lg-2 control-label">工资</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" name="sal" id="sal" th:value="${userDto.sal}" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group has-warning">
                                    <label class="col-lg-2 control-label">奖金</label>
                                    <div class="col-lg-10">
                                        <input type="text" placeholder="" name="comm" id="comm" th:value="${userDto.comm}" class="form-control">
                                    </div>
                                </div>
                                <div class="form-group has-warning">
                                    <label class="col-lg-2 control-label">部门名称</label>
                                    <div class="col-lg-10">
                                        <select id="dname" class="form-control" name="deptno">
                                            <option value="0">请选择部门</option>
                                            <option th:each="dept:${deptList}" th:value="${dept.deptno}" th:text="${dept.dname}"></option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <div class="col-lg-offset-2 col-lg-10">
                                        <button class="btn btn-primary" type="button" id="tijiao">修改</button>
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                                        <a th:href="@{/boss_delete(id=${userDto.id})}"><button class="btn btn-danger" type="button">删除</button></a>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </section>
                </div>
            </div>
        </div>
        <!--body wrapper end-->

        <!--footer section start-->
        <footer>
            2020 &copy; AdminEx by ThemeBucket </a>
        </footer>
        <!--footer section end-->


    </div>
    <!-- main content end-->
</section>

<!-- Placed js at the end of the document so the pages load faster -->
<div th:replace="commons :: js"></div>

<script>
    /**
     * 判断输入框是否为空
     */
    $(function () {
        $("body").on("click","#tijiao",function () {
            checknull();
        });

        /**
         * 判断输入框输入是否为空,为空则输入框变为红色,否则绿色
         */
        $("body").on("blur","#email",function () {
            var email = $("[name='email']").val();
            var isEmail =  /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
            if(email==""||!isEmail.test(email)){
                $("#email").css({
                    'border-color':'red'
                });
            }else{
                $("#email").css({
                    'border-color':'green'
                });
            }
        });
        $("body").on("blur","#tel",function () {
            var tel = $("[name='tel']").val();
            var istel =  /(^1[0-9]{10}$)/;
            if(tel==""||!istel.test(tel)){
                $("#tel").css({
                    'border-color':'red'
                });
            }else{
                $("#tel").css({
                    'border-color':'green'
                });
            }
        });
        $("body").on("blur","#address",function () {
            var address = $("[name='address']").val();
            if(address==""){
                $("#address").css({
                    'border-color':'red'
                });
            }else{
                $("#address").css({
                    'border-color':'green'
                });
            }
        });
        $("body").on("blur","#username",function () {
            var username = $("[name='username']").val();
            if(username==""){
                $("#username").css({
                    'border-color':'red'
                });
            }else{
                $("#username").css({
                    'border-color':'green'
                });
            }
        });
    });

    function checknull() {
        var id = $("[name='id']").val();
        var username = $("[name='username']").val();
        var ename = $("[name='ename']").val();
        var email = $("[name='email']").val();
        var tel = $("[name='tel']").val();
        var address = $("[name='address']").val();
        var mgr = $("[name='mgr']").val();
        var hiredate = $("[name='hiredate']").val();
        var sal = $("[name='sal']").val();
        var comm = $("[name='comm']").val();
        var deptno = $("[name='deptno']").val();
        var dname = $("[name='dname']").val();
        var mark = $("[name='mark']").val();
        var isEmail =  /^([\.a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/;
        var istel =  /(^1[0-9]{10}$)/;
        if(username==""||ename==""||id==""||email==""||tel==""||address==""||mgr==""||sal==""||comm==""||deptno==""||hiredate==""||dname==""||mark==""){
            alert("未输入完整!");
            return false;
        }else if(!isEmail.test(email)){
            alert("邮箱格式错误!");
            return false;
        }else if(!istel.test(tel)){
            alert("手机号格式错误!");
            return false;
        }
        else{
            $("#form").submit();
        }
    };
</script>
<!--common scripts for all pages-->

</body>
</html>
